package com.example.myenglishbook.database;

import android.content.Context;

import androidx.annotation.NonNull;
import androidx.room.Database;
import androidx.room.Room;
import androidx.room.RoomDatabase;
import androidx.room.migration.Migration;
import androidx.sqlite.db.SupportSQLiteDatabase;

@Database(entities = {Words.class},version = 1,exportSchema = false)
public abstract class WordsDatabase extends RoomDatabase {
    private static WordsDatabase INSTANCE;

    public static WordsDatabase getINSTANCE(Context context) {
        if(INSTANCE==null){
            INSTANCE= Room.databaseBuilder(context.getApplicationContext(),WordsDatabase.class,"my_english_words")
                    //.addMigrations(MIGRATION_1_2)更新数据库
                    .build();
        }
        return INSTANCE;
    }

    public abstract WordsDao getWordsDao();

    /*static Migration MIGRATION_1_2=new Migration(1,2) {//数据库迁移
        @Override
        public void migrate(@NonNull SupportSQLiteDatabase database) {
            database.execSQL("ALTER TABLE WORDS ADD COLUMN COL_NAME INTEGER NOT NULL DEFAULT 1");
        }
    };*/
}
